#include<stdio.h>
#include<unistd.h>
#include<pthread.h>

void *entry(void *arg){
    pthread_t tid=pthread_self();//获取当前线程的线程ID
    pthread_detach(pthread_self());
    printf("tid:%p",(void*)tid);
    int count=1;
    while(1){
        printf("I am normal thread!%s\n",(char*)arg);
        sleep(1);
        if(count++==5){
        pthread_exit(NULL);   
        }
    }
    return NULL;
}
int main(){
    char *data="还有一小时!!!";
    pthread_t tid;//用于获取被创建出来的进程ID
    int ret=pthread_create(&tid,NULL,entry,(void*)data);
    if(ret!=0){
        printf("create pthread failed!!!\n");
        return -1;
    }
    //pthread_join(tid,NULL);
    //pthread_detach(tid);
    printf("main:%p\n",tid);//打印共享区中线程的首地址
    while(1){
        printf("I am main thread!\n");
        sleep(1);
        //pthread_cancel(tid);
    }
    return 0;
}
